#######################################
# PLOT WWI MILITARY VICTIMS IN FRANCE #
#######################################

# Author: Kasia Nalewajko
# First created: 28 August 2023
# Replicated: 12 June 2024

rm(list = ls())

# LOAD PACKAGES -----------------------------------------------------------

if (!require("dplyr")) install.packages("dplyr")
if (!require("viridis")) install.packages("viridis")
if (!require("ggplot2")) install.packages("ggplot2")
if (!require("sf")) install.packages("sf")

# LOAD DATA ---------------------------------------------------------------

load("./00 SUBMITTED/00 APSR final/04 replication_files/01 data/main.Rda")
frcantons1940 <- sf::read_sf("./00 SUBMITTED/00 APSR final/04 replication_files/01 data/Gay_CANTONS_1940/CANTONS_1940.shp")

# SUMMARISE VICTIM STATISTICS

france1940_sf <- st_as_sf(frcantons1940)

vic_summary <- main %>%
  dplyr::select(deppct, mpf1000) 

france1940_sf <- left_join(france1940_sf, vic_summary)

france1940_sf %>%
  # filter(log(mpf1000+1) > 0) %>%
  ggplot() +
  geom_sf() +
  aes(fill = log(mpf1000+1)) +
  scale_fill_viridis(
    option = "inferno",
    trans = "reverse",
    na.value="gray90"
  ) +
  theme_bw() +
  theme(axis.text.x=element_blank(),
        axis.text.y=element_blank(),
        legend.position="bottom") +
  labs(title = "",
       subtitle = "",
       fill = "Number victims per 1,000 inhabitants (logged)",
       x = "",
       y = "")

ggsave(
  "A3_WW1victims_cantons.png",
  plot = last_plot(),
  path = "./00 SUBMITTED/00 APSR final/03 dataverse_online_appendix/maps",
  width = 15,
  height = 15,
  units = "cm",
  dpi = 300
)
